/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

void reorderList(struct ListNode* head)
{
    struct ListNode* fast=head,*slow=head;
    while(fast&&fast->next)
    {
        fast=fast->next->next;
        slow=slow->next;
    }
    struct ListNode*p1=NULL,*p2=slow,*p3=p2->next;
    while(p2)
    {
        p2->next=p1;
        p1=p2;
        p2=p3;
        if(p3)
        {
            p3=p3->next;
        }
    }
    struct ListNode*pa=head,*pb=head->next,*p0=p1;
    while(pb)
    {
        if(p1)
        {
            p1=p1->next;
        }
        pa->next=p0;
        if(p0)
        {
            p0->next=pb;
        }
        pa=pb;
        pb=pb->next;
        p0=p1;
    }
    return head;
}


